package com.aistar.service.impl;

import com.aistar.mapper.DynamicCommentMapper;
import com.aistar.pojo.DynamicComment;
import com.aistar.service.DynamicCommentService;
import com.aistar.util.MessageUtil;
import com.aistar.util.ServerResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class DynamicCommentServiceImpl implements DynamicCommentService {
    private final DynamicCommentMapper dynamicCommentMapper;

    @Autowired
    public DynamicCommentServiceImpl(DynamicCommentMapper dynamicCommentMapper) {
        this.dynamicCommentMapper = dynamicCommentMapper;
    }

    @Override
    public ServerResponse add(DynamicComment dynamicComment) {
        int rows = dynamicCommentMapper.insertSelective(dynamicComment);
        if (rows > 0)
            return ServerResponse.addSuccess();
        return ServerResponse.addFailed();
    }

    @Override
    public ServerResponse modify(DynamicComment dynamicComment) {
        int rows = dynamicCommentMapper.updateByPrimaryKeySelective(dynamicComment);
        if (rows > 0)
            return ServerResponse.modifySuccess();
        return ServerResponse.modifyFailed();
    }

    @Override
    public ServerResponse delete(Integer dynamicCommentId) {
        DynamicComment comment = new DynamicComment();
        comment.setDynamicCommentId(dynamicCommentId);
        comment.setStatus(MessageUtil.STATUS_FAIL);
        int rows = dynamicCommentMapper.updateByPrimaryKeySelective(comment);
        if (rows > 0)
            return ServerResponse.deleteSuccess();
        return ServerResponse.deleteFailed();
    }
}
